$(document).ready(function(){
	$( ".jeton" ).draggable({revert: "invalid"});


		var caseTiree = $("#caseTiree").text();
		var caseNom = ".val";
		var caseDropUp = caseNom + caseTiree;
		var caseDropDown = caseNom + caseTiree;

		while($(caseDropUp).children().length == $(caseDropUp).length){
			caseTiree++;
			caseDropUp = caseNom + caseTiree;
			if(caseTiree == 20)
				break;
		}
		
		while($(caseDropDown).children().length == $(caseDropDown).length){
			caseTiree--;
			caseDropDown = caseNom + caseTiree;
			if(caseTiree == 0)
				break;
		}

		$( caseDropUp ).droppable({
			accept: function(){
				if($(this).children().length < 1){
					return ".jeton";
				}
			},
			drop: function( event, ui ) {
				ui.draggable.appendTo( $(this) ).removeAttr("style").addClass("pull-right").css({
					 position: "relative"
				});
			}
		});
		
		$( caseDropDown ).droppable({
			accept: function(){
				if($(this).children().length < 1){
					return ".jeton";
				}
			},
			drop: function( event, ui ) {
				ui.draggable.appendTo( $(this) ).removeAttr("style").addClass("pull-right").css({
					 position: "relative"
				});
			}
		});
	
});